feat(agent): add subagent model setting#3077
Closed
charlesvien wants to merge 5 commits into
Closed
Conversation
|
React Doctor found no issues in the changed files. 🎉 Reviewed by React Doctor for commit |
Contributor
|
Reviews (1): Last reviewed commit: "add subagent model setting" | Re-trigger Greptile |
Contributor
|
Reviews (2): Last reviewed commit: "store subagent model in app settings" | Re-trigger Greptile |
43300ed to
9a06e92
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Subagents inherit the main session model, which defaults to Opus (
claude-opus-4-8). A dynamic-workflow research fan-out of 30+ agents runs entirely on the most expensive tier, and there is no setting anywhere in the product to change that. The only exception today is the hardcodedph-exploreagent pinned to sonnet.Changes
buildSessionOptionsinjectsCLAUDE_CODE_SUBAGENT_MODELinto every spawned Claude CLI env. The CLI applies it as a hard override for all subagents, including dynamic-workflowagent()fan-outs. Resolution order at spawn: a hand-written env entry in the merged.claude/settings.jsonlayers (read only, never written; mirrors how the settingsmodelbeats the session meta model), then the host-provided app setting, then a pre-set process env var (cloud orchestrator or shell), then the newDEFAULT_SUBAGENT_MODEL = "sonnet".subagentModelkey in the electron-store settings behindIWorkspaceSettings(same home as worktree location and auto-suspend). Nothing writes to Claude settings files.AgentServicereads the stored value and threads it into session_metaassubagentModelon all three start paths (new, resume, imported), the same channel the mainmodeluses, so new and reconnected sessions pick up changes.agent.getSubagentModel/agent.setSubagentModeltRPC procedures forward toAgentService, which forwards toIWorkspaceSettings.toSdkModelId.Notes:
inheritsemantics change, so "Inherit main model" forces subagents onto the main model rather than restoring per-agent frontmatter. That matches the UI label;ph-explorefollows the main model in inherit mode until the CLI is bumped.POSTHOG_CODE_SUBAGENT_MODELtask-run field in the backend. Interim escape hatch: the Sandbox Environments environment variables field.availableModelsallowlist only gates the human-facing pickers, not this env var. Documented, not enforced, in v1.How did you test this?
pnpm --filter @posthog/agent test: 836 passed, including cases for the spawn resolution order (settings env > host-provided setting > process env > default), the gateway-id-to-aliasit.eachmapping and the user-layer env merge intoSettingsManager.pnpm --filter @posthog/workspace-server test: 597 passed, includingAgentService.getSubagentModel/setSubagentModelforwarding toIWorkspaceSettingsand_meta.subagentModelthreading (present when set, absent when unset).pnpm --filter @posthog/uicomponent tests: 8 cases forSubagentModelSetting(default/inherit/catalog display, raw-value fallback, disabled while loading and mutating, error text, missing catalog).pnpm typecheck(22 tasks),biome linton all touched files andnode scripts/check-host-boundaries.mjs(no new violations).CLAUDE_CODE_SUBAGENT_MODELappears in the bundled 2.1.170 CLI binary.Automatic notifications